package data
{
	import events.ItemEvent;
	import events.MutiPropertyEvent;
	
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;

	public class PlayerInfo extends MutiProCommitObject
	{
		public function PlayerInfo()
		{
		}
		
		public var id:int;
		
		protected var _nickname:String;
		public static var P_nickname:String='nickname';
		public function get nickname():String
		{
			return _nickname;
		}
		
		public function set nickname(value:String):void
		{
			if (_nickname == value)
				return;
			_lastPropertys[P_nickname]=_nickname;
			_nickname=value;
			onPropertiesChanged(P_nickname);
		}
		
		protected var _soldiers:Dictionary = new Dictionary();
		public static var P_soldiers:String='soldiers';
		public function get soldiers():Dictionary
		{
			return _soldiers;
		}
		
		public function addSoldier(soldierInfo:SoldierInfo):void
		{
			_soldiers[soldierInfo.id] = soldierInfo;
			dispatchEvent(new ItemEvent(ItemEvent.ADD_ITEM,soldierInfo));
		}
		
		public function removeSoldier(soldierInfo:SoldierInfo):void
		{
			delete _soldiers[soldierInfo.id];
			dispatchEvent(new ItemEvent(ItemEvent.REMOVE_ITEM,soldierInfo));
		}
		
		public function get hero():HeroInfo
		{
			for each(var o:HeroInfo in _soldiers)
			{
				if(o != null)return o;
			}
			return null;
		}
	}
}